const http = require('utils/http.js')
App({
  onLaunch: function (options) {
    http.get("/api/index/getCustomerInfo").then( res => {
      if (res.code == 200) {//wxmchid
        this.globalData.customer = res.data
        //console.log(res.result.wxmchid)
        if (this.userInfoReadyCallback) {
          this.userInfoReadyCallback(res)
        }
      }
    })

    // 登录
    wx.login({
      success: data => {
        //console.log(data)
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        http.get('/api/user/login', data).then(res => {
          if (res.code == 200) {
            wx.setStorageSync("token", res.data);
            //wx.setStorageSync("userId", res.result.userid);
          }
        })
      }
    })

    // 获取系统状态栏信息
    wx.getSystemInfo({
      success: e => {
        this.globalData.StatusBar = e.statusBarHeight;
        let capsule = wx.getMenuButtonBoundingClientRect();
        if (capsule) {
         	this.globalData.Custom = capsule;
        	this.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;
        } else {
        	this.globalData.CustomBar = e.statusBarHeight + 50;
        }
      }
    })
  },
  onShow: function () {
    // var myPluginInterface = requirePlugin('paymentIntegral');
    // myPluginInterface.getLocation('openid').then(res => {
    //   console.log(res)
    // })
  },
  globalData: {
    userInfo: wx.getStorageSync("userInfo"),
    ggBannerBool: true
  }
})
